#include <bst.h>

static void middle_iterate_node(const bst_node_t* node_pn,
				deal_bst_node_ft deal_f) {
	if (node_pn == nullptr) {
		return;
	}
	const bst_node_t* node_p = node_pn;
	middle_iterate_node(node_p->left_pn, deal_f);
	deal_f(node_p);
	middle_iterate_node(node_p->right_pn, deal_f);
}

void bst_middle_iterate(const bst_t* bst_p, deal_bst_node_ft deal_f) {
	middle_iterate_node(bst_p->root_pn, deal_f);
}

static void front_iterate_node(const bst_node_t* node_pn,
			       deal_bst_node_ft deal_f) {
	if (node_pn == nullptr) {
		return;
	}
	const bst_node_t* node_p = node_pn;
	deal_f(node_p);
	front_iterate_node(node_p->left_pn, deal_f);
	front_iterate_node(node_p->right_pn, deal_f);
}

void bst_front_iterate(const bst_t* bst_p, deal_bst_node_ft deal_f) {
	front_iterate_node(bst_p->root_pn, deal_f);
}
